<template>
  <el-dialog
    title="合同补充"
    v-model="visible"
    width="65%"
    destroy-on-close
    @closed="$emit('closed')"
  >
    <el-form
      :model="form"
      :rules="rules"
      ref="dialogForm"
      label-width="auto"
      label-position="right"
    >
      <el-form-item label="补充金额" prop="">
        <el-input
          v-model="form.supplementMoney"
          clearable
          placeholder="请输入补充金额"
          oninput="value=value.replace(/^\D*([0-9]\d*\.?\d{0,2})?.*$/,'$1')"
          @blur="form.supplementMoney = $event.target.value"
        >
          <template #append>元</template>
        </el-input>
      </el-form-item>
      <el-form-item label="补充条款" prop="" style="width: 100%">
        <sc-editor
          v-model="form.supplementArticle"
          placeholder="请输入补充条款"
          :height="650"
          :toolbar="toolbar"
        ></sc-editor>
      </el-form-item>
    </el-form>

    <template #footer>
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" :loading="isSaveing" @click="submit()"
        >保 存</el-button
      >
    </template>
  </el-dialog>
</template>

<script>
import { defineAsyncComponent } from 'vue'
const scEditor = defineAsyncComponent(() => import('@/components/scEditor'))
export default {
  emits: ['success', 'closed'],
  data () {
    return {
      visible: false,
      isSaveing: false,
      //表单数据
      form: {
        id: '',
        supplementMoney: '',//补充金额
        supplementArticle: '',//补充条款
      },
      //验证规则
      rules: {
        supplementMoney: [
          { required: true, message: '请输入合同补充金额' }
        ],
        supplementArticle: [
          { required: true, message: '请输入合同补充条款' }
        ],
      },
      toolbar: [
        'undo redo |  forecolor backcolor bold italic underline strikethrough link | blocks fontfamily fontsize | \
					alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | pagebreak | \
					image  table  preview | selectall fullscreen'
      ]
    }
  },
  components: {
    scEditor
  },
  mounted () {

  },
  methods: {
    //显示
    open (data) {
      this.visible = true
      this.form.id = data.id
      return this
    },
    //表单提交方法
    submit () {
      this.$refs.dialogForm.validate(async (valid) => {
        if (valid) {
          this.isSaveing = true
          let res = await this.$API.contract.addSupplement.post(this.form)
          this.isSaveing = false
          if (res.code == 200) {
            this.$emit('success', this.form, this.mode)
            this.visible = false
            this.$message.success("操作成功")
          }
        }
      })
    },
    //表单注入数据
    setData (data) {
      this.form = data
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
